<template>
  <div class="customer-container">
    <!-- 搜索区域 -->
    <ContentWrap class="search-wrapper">
      <!-- 搜索头部 -->
      <div class="search-header">
        <div class="header-icon">
          <Icon icon="ep:user" />
        </div>
        <div class="header-content">
          <h3 class="search-title">客户管理</h3>
          <p class="search-subtitle">管理和查看所有客户信息</p>
        </div>
      </div>

      <!-- 搜索工作栏 -->
      <div class="search-form-container">
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          label-width="100px"
          label-position="left"
          class="enhanced-search-form"
        >
          <div class="form-grid">
            <el-form-item label="客户名称" prop="name" class="form-item">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入客户名称"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:user" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="客户需求" prop="demand" class="form-item">
              <el-input
                v-model="queryParams.demand"
                placeholder="请输入客户需求"
                clearable
                @keyup.enter="handleQuery"
                class="enhanced-input"
              >
                <template #prefix>
                  <Icon icon="ep:document" />
                </template>
              </el-input>
            </el-form-item>

            <el-form-item label="终端类型" prop="clientType" class="form-item">
              <el-select
                v-model="queryParams.clientType"
                placeholder="请选择终端类型"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:monitor" />
                </template>
                <el-option label="pc" value="1" />
                <el-option label="h5" value="2" />
                <el-option label="app" value="3" />
              </el-select>
            </el-form-item>

            <el-form-item label="意向等级" prop="level" class="form-item">
              <el-select
                v-model="queryParams.level"
                placeholder="请选择意向等级"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:star" />
                </template>
                <el-option label="重要客户" value="9" />
                <el-option label="无意向" value="0" />
                <el-option label="有意向" value="1" />
                <el-option label="高意向" value="2" />
              </el-select>
            </el-form-item>

            <el-form-item label="表单" prop="hasForm" class="form-item">
              <el-select
                v-model="queryParams.hasForm"
                placeholder="请选择表单"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:document-checked" />
                </template>
                <el-option label="是" value="1" />
                <el-option label="否" value="0" />
              </el-select>
            </el-form-item>

            <el-form-item label="创建时间" prop="createTime" class="form-item">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              />
            </el-form-item>
          </div>

          <div class="form-actions">
            <el-button @click="handleQuery" class="search-btn">
              <Icon icon="ep:search" class="btn-icon" /> 搜索
            </el-button>
            <el-button @click="resetQuery" class="reset-btn">
              <Icon icon="ep:refresh" class="btn-icon" /> 重置
            </el-button>
            <el-button
              type="success"
              plain
              @click="handleExport"
              :loading="exportLoading"
              v-hasPermi="['service:customer:export']"
              class="export-btn"
            >
              <Icon icon="ep:download" class="btn-icon" /> 导出
            </el-button>
          </div>
        </el-form>
      </div>
    </ContentWrap>

    <!-- 列表区域 -->
    <ContentWrap class="table-wrapper">
      <!-- 排序标签 -->
      <div class="sort-tags" v-if="sortTagList.length > 0">
        <div class="tags-header">
          <Icon icon="ep:sort" class="tags-icon" />
          <span class="tags-title">当前排序：</span>
        </div>
        <div class="tags-list">
          <el-tag
            @close="handleCloseTag(tag.label)"
            v-for="(tag, index) in sortTagList"
            :key="index"
            closable
            class="sort-tag"
            type="info"
          >
            {{ tag.name }}
            <el-icon v-if="tag.sort != 'desc'" class="sort-icon">
              <CaretTop />
            </el-icon>
            <el-icon v-else class="sort-icon">
              <CaretBottom />
            </el-icon>
          </el-tag>
        </div>
      </div>

      <!-- 表格 -->
      <div class="table-container">
        <el-table
          border
          @sort-change="sortChange"
          ref="sortTable"
          :header-cell-style="getRowClass"
          v-loading="loading"
          :data="list"
          :stripe="true"
          :show-overflow-tooltip="true"
          class="enhanced-table"
        >
          <el-table-column label="客户名称" align="left" prop="name" width="200px" fixed="left">
            <template #default="scope">
              <div @click="handleCheck(scope.row)" class="customer-name">
                <Icon icon="ep:user" class="name-icon" />
                <el-link type="primary" class="name-link">{{ scope.row.name }}</el-link>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="状态" align="left" prop="status" width="80px" fixed="left">
            <template #default="scope">
              <div class="status-info">
                <el-tag v-if="scope.row.status == 1" size="small" type="success" class="status-tag">
                  <Icon icon="ep:check" class="tag-icon" />
                  在线
                </el-tag>
                <el-tag v-else type="info" size="small" class="status-tag">
                  <Icon icon="ep:close" class="tag-icon" />
                  离线
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="表单" align="left" prop="hasForm" width="80px" fixed="left">
            <template #default="scope">
              <div class="form-info">
                <el-link
                  v-if="scope.row.hasForm == 1"
                  @click="showCustomerForm(scope.row.loginUserId)"
                  class="form-link"
                >
                  <Icon icon="ep:document-checked" class="form-icon" />
                  有
                </el-link>
                <span v-else class="no-data">-</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="手机号" align="left" prop="mobile" width="150px">
            <template #default="scope">
              <div class="mobile-info">
                <Icon icon="ep:phone" class="mobile-icon" />
                <span class="mobile-text">{{ scope.row.mobile || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="意向等级" align="left" prop="level" width="120px">
            <template #default="scope">
              <div class="level-info">
                <el-tag
                  :type="
                    scope.row.level == 9
                      ? 'danger'
                      : scope.row.level == 2
                        ? 'warning'
                        : scope.row.level == 1
                          ? 'primary'
                          : 'info'
                  "
                  size="small"
                  class="level-tag"
                >
                  <Icon icon="ep:star" class="tag-icon" />
                  {{
                    scope.row.level == 9
                      ? '重要客户'
                      : scope.row.level == 0
                        ? '无意向'
                        : scope.row.level == 1
                          ? '有意向'
                          : scope.row.level == 2
                            ? '高意向'
                            : ''
                  }}
                </el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="客户需求" align="left" prop="demand" width="200px">
            <template #default="scope">
              <div class="demand-info">
                <Icon icon="ep:document" class="demand-icon" />
                <span class="demand-text">{{ scope.row.demand || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="备注" align="left" prop="remark" width="200px">
            <template #default="scope">
              <span class="remark-text">{{ scope.row.remark || '-' }}</span>
            </template>
          </el-table-column>

          <el-table-column label="地址" align="left" prop="address" width="200px">
            <template #default="scope">
              <div class="address-info">
                <Icon icon="ep:location" class="address-icon" />
                <span class="address-text">{{ scope.row.address || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="客户IP地址" align="left" prop="ip" width="150px">
            <template #default="scope">
              <div class="ip-info">
                <Icon icon="ep:connection" class="ip-icon" />
                <span class="ip-text">{{ scope.row.ip || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="浏览器标识" align="left" prop="userAgent" width="150px">
            <template #default="scope">
              <span class="user-agent-text">{{ scope.row.userAgent || '-' }}</span>
            </template>
          </el-table-column>

          <el-table-column label="终端类型" align="left" prop="clientType" width="100px">
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.clientType == 1
                    ? 'primary'
                    : scope.row.clientType == 2
                      ? 'success'
                      : 'warning'
                "
                size="small"
                class="client-tag"
              >
                <Icon icon="ep:monitor" class="tag-icon" />
                {{ scope.row.clientType == 1 ? 'PC' : scope.row.clientType == 2 ? 'H5' : 'APP' }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column label="来源网址" align="left" prop="sourceUrl" width="150px">
            <template #default="scope">
              <div class="source-info">
                <Icon icon="ep:link" class="source-icon" />
                <span class="source-text">{{ scope.row.sourceUrl || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            sortable="custom"
            label="创建时间"
            align="left"
            :formatter="dateFormatter"
            prop="createTime"
            width="180px"
          >
            <template #default="scope">
              <div class="time-info">
                <Icon icon="ep:calendar" class="time-icon" />
                <span class="time-text">{{
                  dateFormatter(scope.row, null, scope.row.createTime)
                }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" width="280px" fixed="right">
            <template #default="scope">
              <div class="action-buttons">
                <el-button
                  link
                  type="primary"
                  @click="openForm(scope.row.id)"
                  v-hasPermi="['service:customer:update']"
                  class="action-btn"
                >
                  <Icon icon="ep:chat-dot-round" class="btn-icon" />
                  查看聊天
                </el-button>
                <el-button
                  link
                  type="primary"
                  @click="openEdit(scope.row)"
                  v-hasPermi="['service:customer:update']"
                  class="action-btn"
                >
                  <Icon icon="ep:edit" class="btn-icon" />
                  编辑
                </el-button>
                <el-button
                  link
                  type="danger"
                  @click="handleDelete(scope.row.id)"
                  v-hasPermi="['service:customer:delete']"
                  class="action-btn delete-btn"
                >
                  <Icon icon="ep:delete" class="btn-icon" />
                  删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </ContentWrap>

    <!-- 表单记录弹窗 -->
    <Dialog v-model="formVisible" title="表单记录" class="form-dialog">
      <div class="form-records">
        <div class="form-record-item" v-for="(item, index) in formList" :key="index">
          <el-descriptions border :title="'表单' + (index + 1)" class="form-descriptions">
            <el-descriptions-item
              width="120px"
              v-for="(subItem, subIndex) in getForm(item)"
              :key="'sub' + subIndex"
              :label="subItem.formLabel"
              class="form-desc-item"
            >
              {{ subItem.value }}
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
    </Dialog>

    <!-- 其他弹窗组件 -->
    <SessionRecord ref="sessionRecordRef" @success="getList" />
    <Check ref="checkRef" @success="getList" />
    <Edit ref="editRef" @success="getList" />
  </div>
</template>

<script setup lang="ts">
import { CaretTop, CaretBottom } from '@element-plus/icons-vue'
import { dateFormatter } from '@/utils/formatTime'
import SessionRecord from './SessionRecord.vue'
import Check from './Check.vue'
import Edit from './Edit.vue'

import * as CustomerApi from '@/api/service/customer'

defineOptions({ name: 'ServiceCustomer' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: null,
  demand: null,
  hasForm: null,
  level: null,
  ip: null,
  userAgent: null,
  clientType: null,
  sourceUrl: null,
  createTime: [],
  sortStr: '',
  sortFields: {}
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/**
 * 客户表单
 *
 *
 */
const formVisible = ref(false)
const formList = ref([])
const showCustomerForm = async (item) => {
  formVisible.value = true
  formList.value = await CustomerApi.getCustomerForm(item)
}
const getForm = (item) => {
  if (!item) {
    return null
  }
  return JSON.parse(item.formContent)
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    if (Object.keys(queryParams.sortFields).length > 0) {
      queryParams.sortStr = JSON.stringify(queryParams.sortFields)
    }
    const data = await CustomerApi.getCustomerPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

let closeTag = ref()
const sortTagList = reactive([])

/** 处理样式 */
const getRowClass = ({ row, column, rowIndex, columnIndex }) => {
  if (column.property == closeTag.value) {
    column.order = ''
  }
}

/** 标签排序 */
const sortChange = (column) => {
  queryParams.sortFields[column.prop] = column.order == 'descending' ? 'desc' : 'asc'
  let label = column.column.label
  if (sortTagList.findIndex((i) => i.name === label) < 0) {
    sortTagList.push({
      name: label,
      sort: column.order == 'descending' ? 'desc' : 'asc',
      label: column.prop
    })
  } else {
    sortTagList.splice(
      sortTagList.findIndex((i) => i.name === label),
      1,
      {
        name: label,
        sort: column.order == 'descending' ? 'desc' : 'asc',
        label: column.prop
      }
    )
  }

  handleQuery()
  closeTag.value = ''
}

/** 关闭标签 */
const handleCloseTag = (label) => {
  delete queryParams.sortFields[label]
  sortTagList.splice(
    sortTagList.findIndex((i) => i.label === label),
    1
  )
  handleQuery()
  closeTag.value = label
}

const sortTable = ref()
/** 重置按钮操作 */
const resetQuery = () => {
  queryParams.sortFields = {}
  sortTagList.length = 0
  closeTag.value = ''
  sortTable.value.clearSort()
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const sessionRecordRef = ref()
const openForm = (id: number) => {
  sessionRecordRef.value.open(id)
}

/** 打开详情 */
const checkRef = ref()
const handleCheck = (row: object) => {
  checkRef.value.open(row)
}
/** 打开编辑 */
const editRef = ref()
const openEdit = (row: object) => {
  editRef.value.open(row)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await CustomerApi.deleteCustomer(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await CustomerApi.exportCustomer(queryParams)
    download.excel(data, '客户列表.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>

<style lang="scss" scoped>
.customer-container {
  padding: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 8px;
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
}

.search-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  color: white;
  border-radius: 10px;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
  margin-left: 16px;

  @media (max-width: 768px) {
    margin-left: 0;
    text-align: center;
  }
}

.search-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 18px;
  }
}

.search-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-form-container {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 12px;

    @media (max-width: 768px) {
      grid-template-columns: 1fr;
      gap: 16px;
      margin-bottom: 20px;
    }
  }

  .form-item {
    margin-bottom: 0;

    :deep(.el-form-item__label) {
      font-weight: 500;
      color: #374151;
    }
  }
}

.enhanced-input,
.enhanced-select,
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.search-btn {
  background: linear-gradient(135deg, #0052cc 0%, #1d4ed8 100%);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  color: white;

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.reset-btn {
  border: 2px solid #e5e7eb;
  color: #6b7280;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;

  &:hover {
    border-color: #d1d5db;
    color: #374151;
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.export-btn {
  border: 2px solid #10b981;
  color: #10b981;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;

  &:hover {
    background: rgba(16, 185, 129, 0.05);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
}

.sort-tags {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: rgba(0, 82, 204, 0.05);
  border-bottom: 1px solid rgba(0, 82, 204, 0.1);

  @media (max-width: 768px) {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
  }
}

.tags-header {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tags-icon {
  color: #0052cc;
  font-size: 16px;
}

.tags-title {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sort-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-size: 12px;

  .sort-icon {
    font-size: 12px;
  }
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    background: #f8fafc;

    th {
      background: #f8fafc !important;
      color: #374151;
      font-weight: 600;
      border-bottom: 2px solid #e5e7eb;
    }
  }

  :deep(.el-table__row) {
    &:hover {
      background: rgba(0, 82, 204, 0.02) !important;
    }
  }

  :deep(.el-table__cell) {
    padding: 12px 8px;
    border-bottom: 1px solid #f1f5f9;
  }
}

/* 表格内容样式 */
.customer-name {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    color: #0052cc;
  }
}

.name-icon {
  color: #6b7280;
  font-size: 14px;
}

.name-link {
  font-weight: 500;
}

.status-info {
  display: flex;
  align-items: center;
}

.status-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;

  .tag-icon {
    font-size: 12px;
  }
}

.form-info {
  display: flex;
  align-items: center;
}

.form-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
}

.form-icon {
  font-size: 12px;
}

.mobile-info,
.demand-info,
.address-info,
.ip-info,
.source-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.mobile-icon,
.demand-icon,
.address-icon,
.ip-icon,
.source-icon {
  color: #6b7280;
  font-size: 12px;
  flex-shrink: 0;
}

.mobile-text,
.demand-text,
.address-text,
.ip-text,
.source-text {
  color: #1f2937;
  font-weight: 500;
}

.level-info {
  display: flex;
  align-items: center;
}

.level-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;

  .tag-icon {
    font-size: 12px;
  }
}

.client-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;

  .tag-icon {
    font-size: 12px;
  }
}

.time-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.time-icon {
  color: #6b7280;
  font-size: 12px;
}

.time-text {
  color: #1f2937;
  font-weight: 500;
}

.remark-text,
.user-agent-text {
  font-size: 12px;
  color: #1f2937;
  line-height: 1.4;
}

.no-data {
  color: #9ca3af;
  font-size: 12px;
}

.action-buttons {
  display: flex;
  gap: 4px;
  align-items: center;

  @media (max-width: 768px) {
    gap: 8px;
  }
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;

  &:hover {
    background: rgba(0, 82, 204, 0.1);
  }

  .btn-icon {
    font-size: 12px;
  }
}

.delete-btn {
  &:hover {
    background: rgba(239, 68, 68, 0.1);
  }
}

.pagination-wrapper {
  padding: 20px 24px;
  background: white;
  border-top: 1px solid #f1f5f9;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-pagination) {
    justify-content: center;

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 表单记录弹窗样式 */
.form-dialog {
  :deep(.el-dialog) {
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 82, 204, 0.15);
  }

  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, #0052cc 0%, #003d99 100%);
    color: white;
    padding: 20px 24px;
    border-radius: 12px 12px 0 0;

    .el-dialog__title {
      color: white;
      font-weight: 600;
    }

    .el-dialog__headerbtn {
      .el-dialog__close {
        color: white;

        &:hover {
          color: rgba(255, 255, 255, 0.8);
        }
      }
    }
  }
}

.form-records {
  max-height: 60vh;
  overflow-y: auto;
}

.form-record-item {
  margin-bottom: 20px;
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;

  &:last-child {
    margin-bottom: 0;
  }
}

.form-descriptions {
  :deep(.el-descriptions__header) {
    background: #0052cc;
    color: white;
    padding: 12px 16px;
    border-radius: 6px 6px 0 0;

    .el-descriptions__title {
      color: white;
      font-weight: 600;
    }
  }

  :deep(.el-descriptions__body) {
    .el-descriptions__table {
      border-radius: 0 0 6px 6px;
      overflow: hidden;
    }
  }
}

.form-desc-item {
  :deep(.el-descriptions-item__label) {
    background: rgba(0, 82, 204, 0.1);
    color: #0052cc;
    font-weight: 500;
  }

  :deep(.el-descriptions-item__content) {
    background: white;
    color: #1f2937;
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .customer-container {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .search-form-container,
  .table-container,
  .pagination-wrapper {
    background: #374151;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      background: #4b5563;

      th {
        background: #4b5563 !important;
        color: #f9fafb;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .mobile-text,
  .demand-text,
  .address-text,
  .ip-text,
  .source-text,
  .time-text,
  .remark-text,
  .user-agent-text {
    color: #f9fafb;
  }

  .mobile-icon,
  .demand-icon,
  .address-icon,
  .ip-icon,
  .source-icon,
  .time-icon,
  .name-icon {
    color: #d1d5db;
  }

  .form-record-item {
    background: #4b5563;
  }

  .form-desc-item {
    :deep(.el-descriptions-item__content) {
      background: #374151;
      color: #f9fafb;
    }
  }
}
</style>
